﻿<!DOCTYPE html>
<html lang="pt-br">
<head>
    <title>Exemplo de web worker</title>
</head>
<body>
    <section>
    	<h1>Web Worker  &#169;</h1>

        <h2>Esse cara é  <span id="cara"></span></h2>

        <div>
            <button onclick="sendMan('Muda')">Muda-man</button>
            <button onclick="sendMan('Gil')">Gil Bahia</button>
            <button onclick="sendMan('Jhon')">Jhon</button>
        </div>
    </section>

    <script type="text/javascript">
        var webWorker;
        if (typeof (Worker) !== "undefined") {
            webWorker = new Worker("processScript.js");
        }

        function sendMan(str) {
            webWorker.postMessage({nome: str});
        }

        function receiveMessage(e) {
            document.querySelector("#cara").textContent = e.data;
        }
        webWorker.addEventListener("message", receiveMessage, false);
        

        //criando uma url blob
        //var bb = new BlobBuilder();
        //bb.append("onmessage = function(e) { postMessage('msg from worker'); }");
        //var blobUrl = window.URL.createObjectURL(bb);
    </script>

    
</body>
</html>
